package com.lyl.serviceresume.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyl.exception.ZxjyException;
import com.lyl.serviceresume.cloudclient.UcenterClient;
import com.lyl.serviceresume.entity.ResumeUser;
import com.lyl.serviceresume.mapper.ResumeMapper;
import com.lyl.serviceresume.service.ResumeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyl.vo.order.UcenterMemberWebVoOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 雷艳玲
 * @since 2022-07-21
 */
@Service
public class ResumeServiceImpl extends ServiceImpl<ResumeMapper, ResumeUser> implements ResumeService {

    @Autowired
    UcenterClient ucenterClient;

    @Override
    public void pageQuery(Page<ResumeUser> pageParam, ResumeUser resumeUserQuery) {
        QueryWrapper<ResumeUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id", resumeUserQuery.getTeacherId());
        queryWrapper.orderByDesc("gmt_create");

        Integer status= resumeUserQuery.getStatus();
        String resumeName = resumeUserQuery.getResumeName();
        Date gmtCreate = resumeUserQuery.getGmtCreate();
//        String subjectId = courseQuery.getSubjectId();
//
        if (!StringUtils.isEmpty(status)) {
            queryWrapper.eq("status", status);
        }
        if (!StringUtils.isEmpty(resumeName) ) {
            queryWrapper.like("resume_name", resumeName);
        }

        if (!StringUtils.isEmpty(gmtCreate)) {
            queryWrapper.eq("gmt_create", gmtCreate);
        }

        baseMapper.selectPage(pageParam, queryWrapper);
    }

    @Override
    public boolean saveResumeUser(ResumeUser resumeUser) {
        if(StringUtils.isEmpty(resumeUser.getMemberId()))
            throw  new ZxjyException("请先登录");
        // 远程调用用户信息
        UcenterMemberWebVoOrder info = ucenterClient.getInfo(resumeUser.getMemberId());

        resumeUser.setMobile(info.getMobile());
        resumeUser.setTeacherId(1L);// 提交上来统一为admin
        resumeUser.setStatus(1);
        resumeUser.setResumeName("前端5年");
        System.out.println(resumeUser);

        return baseMapper.insert(resumeUser)>0;
    }
}
